package com.suxin;

import com.alibaba.fastjson.JSON;
import org.junit.Test;

import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author Tang
 * @classname NoContextMain
 * @description [  ]
 * @date 2021/3/18 15:54
 */
public class NoContextMain {

    String[] having = new String[]{"03-16", "03-14", "02-27", "02-23", "02-25", "01-16", "01-18", "01-19", "01-20", "01-23", "03-17",
            "01-31", "01-30", "01-22", "01-27", "01-21", "01-25", "01-29", "01-28", "01-15", "01-24", "01-12", "01-14"
    };

    String[] noQ = new String[]{"03-15", "03-12", "03-08", "03-01", "03-04", "03-13", "02-22", "02-24", "03-10", "03-09", "03-05",
            "03-11", "03-03", "03-02","03-06"
    };

    private final String prefix = "oci:product:electrolyzer:history_2021-";

    public static void main(String[] args) {


        LocalDate d1 = LocalDate.of(2021, 4, 8);
        LocalDate d2 = LocalDate.now();

        Map<String, Object> map = new HashMap<>(8);

        while (d1.isBefore(d2)) {
            Random random = new Random();

            List<Map<String, Object>> list = new ArrayList<>(10);

            Map<String, Object> map1 = new HashMap<>(8);
            map1.put("name", "1#锅炉");
            map1.put("value", 1000 + Math.random() * 1500);
            map1.put("uploadTime", d1.toString());
            list.add(map1);

            Map<String, Object> map2 = new HashMap<>(8);
            map2.put("name", "2#锅炉");
            map2.put("value", 1000 + Math.random() * 1500);
            map2.put("uploadTime", d1.toString());
            list.add(map2);

            Map<String, Object> map3 = new HashMap<>(8);
            map3.put("name", "3#锅炉");
            map3.put("value", 70 + Math.random() * 10);
            map3.put("uploadTime", d1.toString());
            list.add(map3);

            Map<String, Object> map4 = new HashMap<>(8);
            map4.put("name", "2#汽轮机");
            map4.put("value", 200 + Math.random() * 50);
            map4.put("uploadTime", d1.toString());
            list.add(map4);

            Map<String, Object> map5 = new HashMap<>(8);
            map5.put("name", "3#汽轮机");
            map5.put("value", 2000 + Math.random() * 200);
            map5.put("uploadTime", d1.toString());
            list.add(map5);

            map.put("date", list);

            System.out.println("结果--->" + JSON.toJSONString(map));

            d1 = d1.plusDays(1);
        }

    }

    @Test
    public void test01(){

        List<String> havingMonth = Arrays.stream(having)
                .map((item) -> "2021-" + item)
                .collect(Collectors.toList());
        havingMonth.addAll(
                Arrays.stream(noQ)
                        .map((item) -> "2021-" + item)
                        .collect(Collectors.toList())
        );

        LocalDate localDate1 = LocalDate.of(2021, 1, 1);
        LocalDate localDate2 = LocalDate.of(2021, 2, 1);

        List<String> monthDays = getMonthDays(localDate1, localDate2);

        monthDays.forEach((item) -> {
            if (havingMonth.contains(item)) { return; }
            // 随机的key
            String randomDate = havingMonth.get(new Random().nextInt(havingMonth.size()));
            // 新key
            String newKey = prefix + item;

            System.out.println(randomDate + "--->" + newKey);
        });

    }


    public static List<String> getMonthDays(LocalDate startDate,LocalDate endDate) {
        List<String> dates = new ArrayList<>(16);
        while (startDate.isBefore(endDate)) {
            dates.add(startDate.toString());
            startDate = startDate.plusDays(1);
        }
        return dates;
    }

}